package JavaSE.WEBLearning.Page185;

import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 *  Java核心技术 185页4-2
 *  程序说明
 *      如果不在命令行中设置任何参数，那么将打印出本地主机的因特网地址
 *      如果在命令行中设置了主机名，将打印出该主机的所有因特网地址（包括IPv6）
 */
public class InetAddressTest {
    public static void main(String[] args) throws UnknownHostException {
        if(args.length > 0) {
            String host = args[0];
            InetAddress[] addresses = InetAddress.getAllByName(host);
            for (InetAddress a : addresses) {
                System.out.println(a);
            }
        } else {
            InetAddress localHostAddress = InetAddress.getLocalHost();
            System.out.println(localHostAddress);
        }
    }
}
